package controllers.route;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import services.RouteService;
import controllers.AbstractController;
import domain.Route;

@Controller
@RequestMapping("/route")
public class RouteController extends AbstractController {
	@Autowired
	private RouteService routeService;

	public RouteController() {
		super();
	}

	//Listing
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public ModelAndView list(@RequestParam int eventId) {
		ModelAndView result;
		Collection<Route> routes = routeService.findByEventId(eventId);

		result = new ModelAndView("route/list");
		result.addObject("requestURI", "route/list.do");
		result.addObject("routes", routes);
		result.addObject("eventId", eventId);
		result.addObject("ordered", false);
		result.addObject("backURI", "/event/edit.do?eventId="+eventId);
		
		
		return result;
	}
	
	@RequestMapping(value = "/ordered/list", method = RequestMethod.GET)
	public ModelAndView orderedList() {
		ModelAndView result;
		Collection<Route> routes = routeService.findAllOrderedByRating();

		result = new ModelAndView("route/list");
		result.addObject("requestURI", "ordered/list.do");
		result.addObject("routes", routes);
		result.addObject("ordered", true);
		result.addObject("backURI", "/welcome/index.do");
		return result;
	}

}
